package com.yonyou.pmclouds.problemlog.process;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogBillStatus;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogVO;
import com.yonyou.pmclouds.repairlog.entity.RepairLogVO;
import com.yonyou.pmclouds.repairlog.service.rmiitf.RepairLogService;
/**
 * 问题记录验收通过后修改本次整改记录状态
 * @author fangpengc
 *
 */
@Component
public class RepairPassAfterProcess implements SingleProcessor<ProblemLogVO>{
    @Autowired
    private RepairLogService repairService;
    @Override
    public void process(ProblemLogVO vo, ProblemLogVO orig) throws BusinessException {
        refreshRepairStatus(vo);
    }
    
    /**
     *  修改本次的整改记录【状态变为通过】
     * @param vo
     * @throws BusinessException
     */
    private void refreshRepairStatus(ProblemLogVO vo) throws BusinessException {
        RepairLogVO[] repairlogs = repairService.query(vo.getPk_problem());
        String pk_repair = null;
        for (RepairLogVO repairLogVO : repairlogs) {
            byte billstatus = repairLogVO.getBillstatus();
            if(ProblemLogBillStatus.STATUS_INIT == billstatus) {
               pk_repair = repairLogVO.getPk_repair();
                break;
            }
        }
        RepairLogVO newRepairVO = repairService.queryOne(pk_repair);
        newRepairVO.setBillstatus(ProblemLogBillStatus.STATUS_PASS);
        repairService.update(newRepairVO, new String[]{RepairLogVO.BILLSTATUS});
    }
}
